package com.base.po.tbk_sdk;

import com.alibaba.fastjson.JSON;
import com.base.helper.WebHelper;
import com.base.po.rebate.tb.Data3;
import com.base.po.rebate.tb.Tbk_p_link;
import com.base.po.tbk.ZtkChainChange;
import com.base.po.tbk.ZtkChainChangeContent;
import net.sf.json.JSONObject;

/**
 * 折淘客
 */
public class ZtkUtil {
    // 折淘客公用变量
    private static String CHAIN_CHANGE_URL = "https://api.zhetaoke.com:10001/api/open_gaoyongzhuanlian.ashx"; // 高佣转链API
    private static String APPKEY = "a0547767cd924cae9d9a9c91d0afc276";
    private static String SID = "40470";
    private static String PID = "mm_101082177_39184040_145912073";

    public static Data3 chainChange(String numIid){
        Data3 data3 = new Data3();

        String param = "appkey=" + APPKEY + "&sid=" + SID + "&pid=" + PID + "&num_iid=" + numIid + "&signurl=5";
        String ztkResponse = WebHelper.GetData(CHAIN_CHANGE_URL, param);
        ZtkChainChange ztkChainChange = JSON.parseObject(ztkResponse, ZtkChainChange.class);
        ZtkChainChangeContent ztkContent = ztkChainChange.getContent().get(0);
        data3.setCategory_id(ztkContent.getLevel_one_category_id());
        data3.setCoupon_click_url(ztkContent.getCoupon_click_url());
        data3.setHas_coupon(ztkContent.getCoupon_click_url() == null ? false : true);
        data3.setItem_id(ztkContent.getTao_id());
        data3.setItem_url(ztkContent.getItem_url());
        data3.setMax_commission_rate(ztkContent.getMin_commission_rate());
        if (data3.getHas_coupon()) {
            data3.setTpwd(ztkContent.getTkl());
            data3.setYouhuiquan(ztkContent.getCoupon_info_money());
        } else {
            data3.setYouhuiquan("0");
        }

        return data3;
    }
}
